package com.yuwenchao.superafflatus.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author chaooGG
 * @version 1.0
 * @date 2021/6/7 16:20
 */
@Configuration
public class kaptchaConfig {

    @Bean
    Producer verifyCode() {
        Properties properties = new Properties();
        properties.setProperty("kaptcha.image.width", "140");
        properties.setProperty("kaptcha.image.height", "45");
        // 字体大小，默认40px
        properties.setProperty("kaptcha.textproducer.font.size", "35");
        // 字体，默认Arial, Courier
        properties.setProperty("kaptcha.textproducer.font.names", "微软雅黑");
        properties.setProperty("kaptcha.textproducer.char.string", "0123456789");
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        // 文字间隔，默认2
        properties.setProperty("kaptcha.textproducer.char.space", "3");
        // 干扰 颜色，合法值： r,g,b 或者 white,black,blue.默认black
        properties.setProperty("kaptcha.noise.color", "blue");
        Config config = new Config(properties);
        DefaultKaptcha kaptcha = new DefaultKaptcha();
        kaptcha.setConfig(config);
        return kaptcha;
    }
}
